package com.yj.springbootsecuritydemo01.service;

import com.yj.springbootsecuritydemo01.mapper.UserMapper;
import com.yj.springbootsecuritydemo01.pojo.UserDetail;
import com.yj.springbootsecuritydemo01.pojo.UserParam;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;

@Service
public class UserServiceImpl implements UserDetailsService {

    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        UserParam userParam = userMapper.selectUserByUsername(username);
        if (null == userParam){
            throw new UsernameNotFoundException("该用户不存在");
        }


        return new UserDetail(userParam, Collections.emptyList());
    }
}
